<?php

namespace App\ModelFilters;


class ChannelOrderFilter extends BaseFilter
{
    /**
     * Related Models that have ModelFilters as well as the method on the ModelFilter
     * As [relationMethod => [input_key1, input_key2]].
     *
     * @var array
     */
    public $relations = [];


    public function order_sn($value)
    {
        return $this->where('order_sn', $value);
    }
    public function push_order_sn($value)
    {
        return $this->where('push_order_sn', $value);
    }
    public function channel_order_sn($value)
    {
        return $this->where('channel_order_sn', $value);
    }
    public function channel_order_status($value)
    {
        return $this->where('channel_order_status', $value);
    }
    public function product_id($value)
    {
        return $this->where('product_id', $value);
    }
    public function spec_id($value)
    {
        return $this->where('spec_id', $value);
    }
    public function channel_id($value)
    {
        return $this->where('channel_id', $value);
    }
    public function user_id($value)
    {
        return $this->where('user_id', $value);
    }

    public function paramsOrder($param)
    {
        $param = $this->filterEmptyParam($param);
        if (empty($param)) {
            return $this;
        }
        return $this->whereHasIn('order', function ($query) use ($param) {

            if (!empty($param['mobile'])) {
                $mobile_arr = explode(" ", $param['mobile']);
                $query->whereIn('mobile', $mobile_arr);
            }

            if (!empty($param['user_order_sn'])) {
                $query->where('user_order_sn', trim($param['user_order_sn']));
            }
            if (!empty($param['product_id'])) {
                $query->where('product_id', intval($param['product_id']));
            }

            if (!empty($param['face_value'])) {
                $query->where('face_value', trim($param['face_value']));
            }

            if (!empty($param['province_id'])) {
                $query->where('province_id', intval($param['province_id']));
            }

            if (!empty($param['city_id'])) {
                $query->where('city_id', intval($param['city_id']));
            }

            if (!empty($param['isp'])) {
                $query->where('isp', intval($param['isp']));
            }

            if (!empty($param['biz_type'])) {
                $query->where('biz_type', intval($param['biz_type']));
            }

            if (!empty($param['hf_type'])) {
                $query->where('hf_type', intval($param['hf_type']));
            }

            if (!empty($param['is_loop'])) {
                $query->where('is_loop', intval($param['is_loop']));
            }
            return $query;
        });
    }


    public function mobile($value)
    {
        return $this->related('order', 'mobile', '=', $value);
    }

    public function face_value($value)
    {
        return $this->related('order', 'face_value', '=', $value);
    }
    public function province_id($value)
    {
        return $this->related('order', 'province_id', '=', $value);
    }
    public function city_id($value)
    {
        return $this->related('order', 'city_id', '=', $value);
    }

    public function isp($value)
    {
        return $this->related('order', 'isp', '=', $value);
    }
    public function biz_type($value)
    {
        return $this->related('order', 'biz_type', '=', $value);
    }
    public function hf_type($value)
    {
        return $this->related('order', 'hf_type', '=', $value);
    }

    public function is_loop($value)
    {
        return $this->related('order', 'is_loop', '=', $value);
    }
}
